this is code to analyze the data

Figures for 3D Liver Print Systematic Scoping Review

This document provides code for importing and cleaning data from the systematic review that was used to create all figures provided in the submitted manuscript.

Figure 1 - Printing Methods

Figure 1a - Kind of printing method used

print_method <- reconciled %>%  
                  select(study_ID, 
                   `4.1 What kind of printing method is used?_ae684e28-4f90-44ad-9de2-731d076de0b0_Answer`) %>% 
                  separate_rows(`4.1 What kind of printing method is used?_ae684e28-4f90-44ad-9de2-731d076de0b0_Answer`, sep="\\|")


print_method <- print_method %>% 
  mutate(`4.1 What kind of printing method is used?_ae684e28-4f90-44ad-9de2-731d076de0b0_Answer`= recode(`4.1 What kind of printing method is used?_ae684e28-4f90-44ad-9de2-731d076de0b0_Answer`, "Extrusion based" = "Extrusion")) %>% 
  mutate(`4.1 What kind of printing method is used?_ae684e28-4f90-44ad-9de2-731d076de0b0_Answer`= recode(`4.1 What kind of printing method is used?_ae684e28-4f90-44ad-9de2-731d076de0b0_Answer`, "Inject based" = "Injection"))

t1 <- table(print_method$`4.1 What kind of printing method is used?_ae684e28-4f90-44ad-9de2-731d076de0b0_Answer`)

#t1# manually set levels 

t1_sorted<- t1 %>% as.data.frame() %>% arrange(factor(Var1, levels = c("Stereolithography", "Extrusion", "Injection", "Other", "Unclear")))

data_bar1 <- t1_sorted$Freq
names(data_bar1) <- t1_sorted$Var1


# barplot(data_bar13)
text(x = barplot(
#  colnames<-(t(t13_sorted[-1]), t13_sorted[,1]), 
 # 'labels' <- (t(t13_sorted[-1]), t13_sorted[,1])), 
  # t(as.matrix(t13_sorted)), 
   data_bar1,
  ylab = "Number of Studies", ylim=c(0, max(data_bar1) + 10), cex.names=1 , col = "#fb9a99", #main = "What kind of printing method was used?"
  ), y = data_bar1 + 2, labels = data_bar1, 
  cex = 1)

# text(x = barplot(t1, ylab = "Number of studies", ylim=c(0, max(t1) + 10), cex.names=0.8, col = "green", main = "What kind of printing method was used?", las=0), y = t1 + 2, labels = t1, cex = 0.8 )

Figure 1b - What forms are printed with the ink?

# Data cleaning
# Those with a semicolon response ; should now be called "combo"
# responses separate with a pipe should be merged when they are saying the same thing. 
printer_forms <- reconciled %>% 
  mutate(`4.1.4 What kind of forms are printed with this ink?_01d3ca37-1e2f-4087-8f39-c183f98f0c4e_Answer`= recode(`4.1.4 What kind of forms are printed with this ink?_01d3ca37-1e2f-4087-8f39-c183f98f0c4e_Answer`, "Grid|Grid" = "Grid")) %>% 
  mutate(`4.1.4 What kind of forms are printed with this ink?_01d3ca37-1e2f-4087-8f39-c183f98f0c4e_Answer`= recode(`4.1.4 What kind of forms are printed with this ink?_01d3ca37-1e2f-4087-8f39-c183f98f0c4e_Answer`, "lobular liver|lobular liver" = "lobular liver")) %>% 
  mutate(`4.1.4 What kind of forms are printed with this ink?_01d3ca37-1e2f-4087-8f39-c183f98f0c4e_Answer`= recode(`4.1.4 What kind of forms are printed with this ink?_01d3ca37-1e2f-4087-8f39-c183f98f0c4e_Answer`, "Other|Other" = "Other")) %>% 
  mutate(`4.1.4 What kind of forms are printed with this ink?_01d3ca37-1e2f-4087-8f39-c183f98f0c4e_Answer`= recode(`4.1.4 What kind of forms are printed with this ink?_01d3ca37-1e2f-4087-8f39-c183f98f0c4e_Answer`, "Grid;Other" = "Combination")) %>% 
  mutate(`4.1.4 What kind of forms are printed with this ink?_01d3ca37-1e2f-4087-8f39-c183f98f0c4e_Answer`= recode(`4.1.4 What kind of forms are printed with this ink?_01d3ca37-1e2f-4087-8f39-c183f98f0c4e_Answer`, "lobular liver;Other" = "Combination")) 

printer_forms <-  printer_forms %>% 
mutate(`4.1.4 What kind of forms are printed with this ink?_01d3ca37-1e2f-4087-8f39-c183f98f0c4e_Answer`= recode(`4.1.4 What kind of forms are printed with this ink?_01d3ca37-1e2f-4087-8f39-c183f98f0c4e_Answer`, "lobular liver" = "Lobular Liver"))

t4 <-table(printer_forms$`4.1.4 What kind of forms are printed with this ink?_01d3ca37-1e2f-4087-8f39-c183f98f0c4e_Answer`)

t4_sorted<- t4 %>% as.data.frame() %>% arrange(factor(Var1, levels = c("Grid", "Lobular Liver", "Toroids", "Combination", "Other")))

data_bar4 <- t4_sorted$Freq
names(data_bar4) <- t4_sorted$Var1

text(x = barplot(
#  colnames<-(t(t13_sorted[-1]), t13_sorted[,1]), 
 # 'labels' <- (t(t13_sorted[-1]), t13_sorted[,1])), 
  # t(as.matrix(t13_sorted)), 
   data_bar4,
  ylab = "Number of Studies", ylim=c(0, max(data_bar4) + 10), cex.names=1 , col = "#fb9a99"
  #, main = "What kind of forms are printed with this ink?"
  ), y = data_bar4 + 2, labels = data_bar4, 
  cex = 1)

# text(x = barplot(t4, ylab = "Number of studies", ylim=c(0, max(t4) + 10), cex.names=.8 , col = "green", main = "What kind of forms are printed with this ink?"), y = t4 + 2, labels = t4, cex = 0.8)

change order to: ” Grid - Lobular Liver - Toroids - Combination - Other” - done ABB

Figure 1c - Which printing methods are used which which bioink?

Interactive sankey diagram - hover over each section to see the number of experiments in each category.

library(plotly)
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
#### prep data for sankey diagram
# type --> 
Print_bioink <- reconciled %>%select(
  study_ID, 
  `4.1 What kind of printing method is used?_ae684e28-4f90-44ad-9de2-731d076de0b0_Answer`,
  `4.1.3 What type of bioink was used?_92421414-c597-4e9c-b720-9bb4318b5483_Answer`, 
  `4.1.3.1.1 If natural bioink, please choose the type._66b761ad-6630-4323-b423-c848a717aae4_Answer`, 
  `4.1.3.1.4 If Synthetic bioink: choose the type _e74ea0e0-a654-4ae2-b59e-2e0b14a4651a_Answer`, 
  `4.1.3.1.2 If Protein based: choose the type._621671b3-9f7e-4a22-80ac-14b02fdd0683_Answer`, 
  `4.1.3.1.3 If Polysaccharides Based: choose the type. _fcea8bcb-da6c-4154-aa44-8ff4734fa4fe_Answer`
)  


Print_bioink_re <- Print_bioink  %>% rename(
  print_method = `4.1 What kind of printing method is used?_ae684e28-4f90-44ad-9de2-731d076de0b0_Answer`,
  typeGeneral_level1 = `4.1.3 What type of bioink was used?_92421414-c597-4e9c-b720-9bb4318b5483_Answer`, 
  typeNatural_level2 = `4.1.3.1.1 If natural bioink, please choose the type._66b761ad-6630-4323-b423-c848a717aae4_Answer`, 
  typeSynthetic_level2 = `4.1.3.1.4 If Synthetic bioink: choose the type _e74ea0e0-a654-4ae2-b59e-2e0b14a4651a_Answer`, 
  typeProtein_level3 = `4.1.3.1.2 If Protein based: choose the type._621671b3-9f7e-4a22-80ac-14b02fdd0683_Answer`, 
  typePoly_level3 = `4.1.3.1.3 If Polysaccharides Based: choose the type. _fcea8bcb-da6c-4154-aa44-8ff4734fa4fe_Answer`
)


#### needs to be 72 rows only!! - MH will supply which combo bioInk to Printer is correct from original study 
# 487b3d85-d671-40f2-8d60-309a6aa9a4f3

# Print_bioink_re <- within(Print_bioink_re, print_method[print_method == "Extrusion based|Stereolithography" & study_ID == '487b3d85-d671-40f2-8d60-309a6aa9a4f3'] <- 'John Smith1')

Print_bioink_re$print_method <- as.character(Print_bioink_re$print_method)

Print_bioink_re <- Print_bioink_re %>% mutate(print_method = ifelse(study_ID == '487b3d85-d671-40f2-8d60-309a6aa9a4f3', "Extrusion based", print_method))

# Print_bioink_re[11, "print_method"] <- "Extrusion based"



Print_bioink1_1 <- Print_bioink_re %>% 
                separate_rows(print_method , sep="\\|")


Print_bioink1_2 <- Print_bioink_re %>%
             separate_rows(typeGeneral_level1, sep="\\|")

Print_bioink1_2$print_method <- as.factor(Print_bioink1_2$print_method)
Print_bioink1_2$typeGeneral_level1 <- as.factor(Print_bioink1_2$typeGeneral_level1 )
  

#   487b3d85-d671-40f2-8d60-309a6aa9a4f3
# extrusion was 
# sterolithography



# summary(Print_bioink1)

Print_bioink1_sankey <- Print_bioink1_2 %>% select(study_ID, print_method, typeGeneral_level1)

Print_bioink1_sankey
## # A tibble: 72 × 3
##    study_ID                             print_method    typeGeneral_level1
##    <chr>                                <fct>           <fct>             
##  1 0b78f899-524b-49df-8b02-bdb64e281ed4 Inject based    Natural           
##  2 f0faaae5-eba2-4213-afe0-d958d5279121 Extrusion based Natural           
##  3 f0faaae5-eba2-4213-afe0-d958d5279121 Extrusion based Synthetic         
##  4 487b3d85-d671-40f2-8d60-309a6aa9a4f3 Extrusion based Natural           
##  5 487b3d85-d671-40f2-8d60-309a6aa9a4f3 Extrusion based Synthetic         
##  6 d21360df-70ad-426a-b86e-b6eccebcbe11 Extrusion based Natural           
##  7 11abf440-c03a-4830-9c5d-4e3688fe8808 Other           Natural           
##  8 6955f074-b9f4-4f46-b6a8-06b49f150239 Inject based    Unclear           
##  9 13e55d40-f8a1-43bd-98ca-32db20c905cd Other           Natural           
## 10 2a8a7137-e063-43ca-aeaa-f6b69913cfd4 Extrusion based Synthetic         
## # ℹ 62 more rows
# create a table of frequencies
freq_table <- Print_bioink1_sankey %>% group_by(print_method, typeGeneral_level1) %>% 
  summarise(n = n())
## `summarise()` has grouped output by 'print_method'. You can override using the
## `.groups` argument.
freq_table <- freq_table %>% 
   mutate(print_method= recode(print_method, "Extrusion based" = "Extrusion")) %>% 
     mutate(print_method= recode(print_method, "Unclear" = "Unclear - Method")) %>% 
  mutate(print_method= recode(print_method, "Inject based" = "Injection")) %>% 
     mutate(typeGeneral_level1= recode(typeGeneral_level1, "Unclear" = "Unclear - Bioink"))


# create a nodes data frame
nodes <- data.frame(name = unique(c(as.character(freq_table$print_method),
                                    as.character(freq_table$typeGeneral_level1))))


# create links dataframe
links <- data.frame(source = match(freq_table$print_method, nodes$name) - 1,
                    target = match(freq_table$typeGeneral_level1, nodes$name) - 1,
                    value = freq_table$n,
                    stringsAsFactors = FALSE)



# Make Sankey diagram
plot_ly(
  type = "sankey",
  orientation = "h",
  node = list(pad = 15,
              thickness = 20,
              line = list(color = "black", width = 0.5),
              label = nodes$name),
  link = list(source = links$source,
              target = links$target,
              value = links$value),
  textfont = list(size = 18, color = "black"),
  width = 820,
  height = 580
) %>%
  layout(
    #title = "Sankey Diagram: Print Method & Ink Type",
         font = list(size = 18),
         margin = list(t = 40, l = 10, r = 10, b = 10))

Figure 1d - What “Other” printed forms are used?

library(stringr)

print_form_comment_other <- tibble( 
   study_ID = reconciled$study_ID, 
   method =  reconciled$`4.1.4 What kind of forms are printed with this ink?_01d3ca37-1e2f-4087-8f39-c183f98f0c4e_Answer`, 
   comment = reconciled$`4.1.4 What kind of forms are printed with this ink?_01d3ca37-1e2f-4087-8f39-c183f98f0c4e_Comments`) 

print_form_comment_other <- print_form_comment_other %>% 
                  separate_rows(method, sep="\\|") %>%  
                  subset(method == "Other")

print_form_comment_other <- print_form_comment_other %>% 
                  separate_rows(comment, sep="\\|")

# remove line breaks
print_form_comment_other$comment <- str_replace_all(print_form_comment_other$comment, "[\n]" , "")

# remove whitespace from start of str
print_form_comment_other$comment <- str_trim(print_form_comment_other$comment, "left")

# remove whitespace from end of str
print_form_comment_other$comment <- str_trim(print_form_comment_other$comment, "right")

# turn variable into a factor to group similar
#print_form_comment_other$comment <- as.factor(print_form_comment_other$comment)

 table(print_form_comment_other$comment)
## 
## Complex,  perfusable architectures                          cruciform 
##                                  1                                  1 
##                              donut                            doplets 
##                                  4                                  1 
##                           droplets                         gear shape 
##                                  8                                  1 
##                          hexagonal               hexagonal constructs 
##                                  1                                  1 
##                          honeycomb                              lines 
##                                  1                                  3 
##                          not clear                  printed on a chip 
##                                  1                                  5 
##                 printing on a chip                          rectangle 
##                                  1                                  1 
##                         sinusoidal                           spheroid 
##                                  1                                  1 
##                          spheroids                             square 
##                                  2                                  1 
##    two-compartment planar geometry 
##                                  7
# is.data.frame(print_form_comment_other)
 
# rename answers to more easily group them
print_form_comment_other <- print_form_comment_other %>% 
      mutate(comment = recode(comment, "doplets" = "droplets")) %>% 
      mutate(comment = recode(comment, "printing on a chip" = "printed on a chip")) %>%   
     mutate(comment = recode(comment, "spheroid" = "spheroids")) %>%
     mutate(comment = recode(comment, "hexagonal constructs" = "hexagonal"))%>%
     mutate(comment = recode(comment, "not clear" = "unclear"))
             

# group by numbers
commentsPrintForm <- print_form_comment_other %>%  group_by(comment) %>% summarise(n_unique = length(unique(study_ID))) %>%  arrange(desc(n_unique))

names(commentsPrintForm) <- c("Printed Form", "Number of Unique Studies")

#install.packages("formattable")
library(formattable)
## 
## Attaching package: 'formattable'
## The following object is masked from 'package:plotly':
## 
##     style
formattable(commentsPrintForm,
            align =c("l", "r"),
            list(`Indicator Name` = formatter(
              "span", 
              style = ~ style(color = "grey",font.weight = "bold", font.size = "16px")), 
              # `Number of Unique Studies`= formatter(style = ~ style( font.weight = "bold")), 
              `Number of Unique Studies`= color_bar("#fb9a99"), 
              table.attr = 'style="font-size: 16px;";\"'
              
))
Printed Form Number of Unique Studies
droplets 6
two-compartment planar geometry 4
printed on a chip 3
spheroids 3
hexagonal 2
lines 2
Complex, perfusable architectures 1
cruciform 1
donut 1
gear shape 1
honeycomb 1
rectangle 1
sinusoidal 1
square 1
unclear 1

CHange “not clear” to “unclear” - done ABB

Figure 2 - BioInks

Figure 2a - What bioinks were used?

Interactive Sunburst plot - hover over each section to see the number of experiments in each category.

#### BIOINK sunburst 

library(dplyr)

# type --> 
bioink <- reconciled %>% select(
  study_ID, 
    `4.1.3 What type of bioink was used?_92421414-c597-4e9c-b720-9bb4318b5483_Answer`, 
    `4.1.3.1.1 If natural bioink, please choose the type._66b761ad-6630-4323-b423-c848a717aae4_Answer`, 
    `4.1.3.1.4 If Synthetic bioink: choose the type _e74ea0e0-a654-4ae2-b59e-2e0b14a4651a_Answer`, 
  `4.1.3.1.2 If Protein based: choose the type._621671b3-9f7e-4a22-80ac-14b02fdd0683_Answer`, 
`4.1.3.1.3 If Polysaccharides Based: choose the type. _fcea8bcb-da6c-4154-aa44-8ff4734fa4fe_Answer`
  )  

# reconciled$`4.1.3.1.4 If Synthetic bioink: choose the type _e74ea0e0-a654-4ae2-b59e-2e0b14a4651a_Answer`

bioink <- bioink  %>% rename(typeGeneral_level1 = `4.1.3 What type of bioink was used?_92421414-c597-4e9c-b720-9bb4318b5483_Answer`, 
   typeNatural_level2 = `4.1.3.1.1 If natural bioink, please choose the type._66b761ad-6630-4323-b423-c848a717aae4_Answer`, 
  typeSynthetic_level2 = `4.1.3.1.4 If Synthetic bioink: choose the type _e74ea0e0-a654-4ae2-b59e-2e0b14a4651a_Answer`, 
  typeProtein_level3 = `4.1.3.1.2 If Protein based: choose the type._621671b3-9f7e-4a22-80ac-14b02fdd0683_Answer`, 
  typePoly_level3 = `4.1.3.1.3 If Polysaccharides Based: choose the type. _fcea8bcb-da6c-4154-aa44-8ff4734fa4fe_Answer`
)



### other is Matrigel
#################### update after discussion with experts on interpretation
bioink_split1 <- separate_rows(bioink, typeGeneral_level1 , sep="\\|")

### fill in NAs 
# turn all cols to character
bioInk_72 <- bioink_split1 %>%
  mutate(across(everything(), as.character))

bioInk_72 <- bioink_split1 %>%
     mutate(
typeNatural_level2 = replace(typeNatural_level2, typeGeneral_level1!="Natural", NA), 
typeSynthetic_level2 = replace(typeSynthetic_level2, typeGeneral_level1!="Synthetic", NA), 
typeProtein_level3 = replace(typeProtein_level3, typeGeneral_level1!="Natural", NA), 
typePoly_level3 =  replace(typePoly_level3, typeGeneral_level1!="Natural", NA),

#typePoly_level3 =  replace(typePoly_level3, typeNatural_level2!="Polysaccharide based", NA), 
#typeProtein_level3 = replace(typeProtein_level3, typeNatural_level2!="Protein based", NA), 
# typePoly_level3 =  replace(typePoly_level3, typeGeneral_level1!="Natural", NA)
            )


 ##### level 2 
 bioInk_72$level2 <- apply(bioInk_72[, c("typeNatural_level2", "typeSynthetic_level2")], 1, 
                           function(i){ paste(na.omit(i), collapse = " ") })

 ##### level 3 
 bioInk_72$level3 <- apply(bioInk_72[, c("typeProtein_level3", "typePoly_level3")], 1,
                       function(i){ paste(na.omit(i), collapse = " ") })



#### rename the columns 
# rename answers to more easily group them
bioInk_73 <- bioInk_72 %>%
      mutate(level3 = recode(level3, "Collagens" = "Collagen")) %>%
      mutate(level3 = recode(level3, "Collagens;Gelatin" = "Collagen+Gelatin")) %>%
      mutate(level3 = recode(level3, "Collagens|Collagens" = "Collagen")) %>%
      mutate(level3 = recode(level3, "Gelatin|Gelatin" = "Gelatin")) %>%
      mutate(level3 = recode(level3, "Gelatin;Silk-fibroin" = "Gelatin+Silk-fibroin")) %>%
      mutate(level3 = recode(level3, "Gelatin;Fibrinogen" = "Gelatin+Fibrinogen")) %>%
  
  mutate(level3 = recode(level3, "Collagens;Gelatin Alginates" = "Collagen+Gelatin+Alginates")) %>%
  mutate(level3 = recode(level3, "Alginates;Other" = "Alginates+Other")) %>%
  mutate(level3 = recode(level3, "Gelatin Alginates" = "Gelatin+Alginates")) %>%
  mutate(level3 = recode(level3, "Collagens Alginates" = "Collagen+Alginates")) %>%
  mutate(level3 = recode(level3, "Fibrinogen Alginates" = "Fibrinogen+Alginates")) %>%
  
  mutate(level3 = recode(level3, "Gelatin Alginates;Other" = "Gelatin+Alginates+Other")) %>%
  mutate(level3 = recode(level3, "Fibrinogen;Other Alginates;Other" = "Fibrinogen+Alginates+Other")) %>%
  mutate(level3 = recode(level3, "Collagens|Collagens Hyaluronic acid|Hyaluronic acid" = "Collagen+Hyaluronic acid")) %>%
  mutate(level3 = recode(level3, "Gelatin;Other Alginates" = "Gelatin+Alginates+Other")) %>%
  
  mutate(level3 = recode(level3, "Gelatin;Other Alginates;Other" = "Gelatin+Alginates+Other")) %>%
  mutate(level3 = recode(level3, "Gelatin Chitosan" = "Gelatin+Chitosan")) %>%
  mutate(level3 = recode(level3, "Gelatin Hyaluronic acid" = "Gelatin+Hyaluronic acid")) %>%
      mutate(level2 = recode(level2, "Poly ethylene glycol (PEG)" = "PEG")) %>% 
      mutate(level2 = recode(level2, "Protein based" = "Protein")) %>% 
      mutate(level2 = recode(level2, "Polysaccharide based" = "Poly")) %>% 
      mutate(level2 = recode(level2, "dECM based" = "dECM")) %>% 
      mutate(level2 = recode(level2, "Protein based;Polysaccharide based" = "Protein+Poly")) %>% 
mutate(level2 = recode(level2, "Protein based;dECM based" = "Protein+dECM")) %>% 
mutate(level2 = recode(level2, "Polysaccharide based;dECM based" = "Poly+dECM")) %>% 
      mutate(level2 = recode(level2, "Protein based;Polysaccharide based;Other" = "Protein+Poly+MatriGel")) %>% 
      mutate(level2 = recode(level2, "Protein based;Polysaccharide based;dECM based" = "Protein+Poly+dECM")) %>% 
      mutate(level2 = recode(level2, "Protein based;Polysaccharide based|Protein based;Polysaccharide based" = "Protein+Poly")) %>% 
      mutate(level2 = recode(level2, "Protein based|Protein based" = "Protein")) %>% 
      mutate(typeGeneral_level1 = recode(typeGeneral_level1, "Not reported" = "NR")        
             )
  
#  Protein based|dECM based
# which(bioInk_72$level2 == "Protein based|dECM based")

# bioInk_72[13, "level2"] <- "Protein based"
# bioInk_72[14, "level2"] <- "dECM based"


bioInk_73[30, "level2"] <- "Protein"
bioInk_73[31, "level2"] <- "dECM "


# other in "not reported" should be removed

#### START PLOTTING

library(dplyr)
library(plotme)
library(plotly)
library(palmerpenguins)

# Create the plots
fig_bioInk_simple <- bioInk_73 %>% 
  count(typeGeneral_level1, level2) %>% 
  plotme::count_to_sunburst()

# Update the colors
fig_bioInk_simple %>% 
    plotly::style(marker = list(colors = c("#a6611a","#dfc27d", "#80cdc1", "#018571"))) 
bioInk_count_suppl <-  bioInk_73 %>%  count(
                       typeGeneral_level1, 
                       level2
                        , level3
                       #,study_ID
                       )%>% 
  plotme::count_to_sunburst()



bioInk_count_suppl %>% 
    plotly::style(marker = list(colors = c("#a6611a","#dfc27d", "#80cdc1", "#018571"))) 
# bioInk_count_simple <-  count(bioInk_73, 
#                        typeGeneral_level1, 
#                        level2
#                        # , level3
#                        #,study_ID
#                        )

# # sunburst plot
# plotme::count_to_sunburst(bioInk_count_simple
#                           
#                           ,sort_by_n = TRUE 
#                           
#                           # ,fill_by_n = TRUE
# 
#                                             )

# link to raw function code: https://github.com/yogevherz/plotme/blob/master/R/count_to_sunburst_treemap.R 

# plotme::count_to_sunburst(bioInk_count_suppl
#                           
#                           ,sort_by_n = TRUE 
#                           
#                           # ,fill_by_n = TRUE
#                           )

Figure 2b - Cell Densities

cellDensity_num <- tibble(
  study_ID = reconciled$study_ID,
  cellDensity = reconciled$`4.1.3.4.1 Please specify the cell density cells/ml!_a995234c-c94e-4d14-8a6c-fe5bd759b928_Answer`)


cellDensity_num <- separate_rows(cellDensity_num, cellDensity, sep="\\|")
cellDensity_num <- separate_rows(cellDensity_num, cellDensity, sep=";")
cellDensity_num <- separate_rows(cellDensity_num, cellDensity, sep=",")

# remove line breaks
cellDensity_num$cellDensity <- str_replace_all(cellDensity_num$cellDensity, "[\n]" , "")

# convert to e+ for scientific notation conversion
cellDensity_num$cellDensity <- str_replace_all(cellDensity_num$cellDensity, "\\*10E" , "e+")

# remove whitespace from start & end of str
cellDensity_num$cellDensity <- str_trim(cellDensity_num$cellDensity, "left")
cellDensity_num$cellDensity <- str_trim(cellDensity_num$cellDensity, "right")


# rename answers to more easily group them
# cellDensity_num <- cellDensity_num %>% 
#       mutate(cellDensity = recode(cellDensity, "1*10E6" = "microarray spotter")) %>% mutate(cellDensity = recode(cellDensity, "scaffold free bioprinting" = "scaffold-free bioprinting"))

options(scipen = 999)


# sorted <- cellDensity_num[order(as.numeric(as.character(cellDensity_num$cellDensity))), ]

freq_table_cell <- cellDensity_num %>% group_by(cellDensity) %>% 
  summarise(n = n())

t16 <- freq_table_cell[order(as.numeric(as.character(freq_table_cell$cellDensity))), ]

 t16 <- table(freq_table_cell$cellDensity)

 
formattable(freq_table_cell)
cellDensity n
0.5e+6 1
1.5e+6 4
1.5e+7 2
1.5e+8 1
10e+5 1
10e+7 1
1e+5 1
1e+6 7
1e+7 5
1e+8 1
2.5e+5 1
2.5e+6 3
2e+5 2
2e+6 7
3.5e+6 1
30e+6 1
3e+5 1
3e+6 4
3e+7 2
4.5e+6 1
4e+5 1
4e+6 1
4e+7 3
5.0e+6 1
5e+5 1
5e+6 4
5e+7 1
6.7e+6 1
6e+6 1
6e+7 1
7e+6 2
8e+6 1
NA 12
# 
# formattable(t16,
#             align =c("l", "r"),
#             list(`Indicator Name` = formatter(
#               "span", 
#               style = ~ style(color = "grey",font.weight = "bold")), 
#               # `Number of Unique Studies`= formatter(style = ~ style( font.weight = "bold")), 
#               `n`= color_bar("lightblue")
#               
# ))
 
#t16

 # text(x = barplot(t16$cellDensity, ylab = "Number of Inks", ylim=c(0, max(t16$n) + 10), cex.names=1 , col = "#b2df8a"
 #                 # , main = "What is the Reported Cell Density"
 #                 ), y = t16$n + 2, labels = t16$cellDensity, cex = 1)



# cellDensity_num$cellDensity <- as.numeric(cellDensity_num$cellDensity)
# 
# hist <- hist(cellDensity_num$cellDensity, breaks = 500, plot = FALSE)
# 
# 
# plot(hist, freq = TRUE, labels = TRUE)

options(scipen = 0)

Figure 2c - Origin of BioInks

# t8 <- table(reconciled$`4.1.3.2. What is the origin of the bioink?_34ef46b6-34ac-4ddb-a5de-07bc74272fca_Answer`)

bioOrigin <-  reconciled %>%select(
  study_ID, 
    `4.1.3.2. What is the origin of the bioink?_34ef46b6-34ac-4ddb-a5de-07bc74272fca_Answer`
 #, `4.1.3 What type of bioink was used?_92421414-c597-4e9c-b720-9bb4318b5483_Answer`
  ) %>%  separate_rows(`4.1.3.2. What is the origin of the bioink?_34ef46b6-34ac-4ddb-a5de-07bc74272fca_Answer`, sep="\\|")


bioOrigin <- bioOrigin %>% mutate(`4.1.3.2. What is the origin of the bioink?_34ef46b6-34ac-4ddb-a5de-07bc74272fca_Answer`= recode(`4.1.3.2. What is the origin of the bioink?_34ef46b6-34ac-4ddb-a5de-07bc74272fca_Answer`, "commercial (ready-to-use)" = "Commercial")) %>% mutate(`4.1.3.2. What is the origin of the bioink?_34ef46b6-34ac-4ddb-a5de-07bc74272fca_Answer`= recode(`4.1.3.2. What is the origin of the bioink?_34ef46b6-34ac-4ddb-a5de-07bc74272fca_Answer`,"custom formulated" = "Custom" ))


t8 <- table(bioOrigin$`4.1.3.2. What is the origin of the bioink?_34ef46b6-34ac-4ddb-a5de-07bc74272fca_Answer`)

t8
## 
##   Commercial       Custom Not reported      Unclear 
##            6           60            2            4
text(x = barplot(t8, ylab = "Number of BioInks", ylim=c(0, max(t8) + 10), cex.names=1 , col = "#b2df8a"
                 #, main = "What is the origin of BioInk"
                 ), y = t8 + 2, 
     labels = t8, cex = 1)

Figure 2d - Available Meta-data for BioInks

Frequency of reporting and what meta-data was actually reported.

# Maren comment: I think what was reported how often would be most interesting. e.g., 10 out of 34 mentioned the concentration, etc
# 4.1.3.2.3.

custom_bioInk <- tibble( 
   study_ID = reconciled$study_ID, 
   infoProivded =  reconciled$`4.1.3.2.3 If custom formulated, which information is provided for the bioink?_fe62b3e4-d8f1-4584-a90d-e07317e4c8e1_Answer`
 # , comment = reconciled$`4.1.3.2.3 If custom formulated, which information is provided for the bioink?_fe62b3e4-d8f1-4584-a90d-e07317e4c8e1_Comments`
 ) 


custom_bioInk <- separate_rows(custom_bioInk, infoProivded, sep="\\|")
custom_bioInk <- separate_rows(custom_bioInk, infoProivded, sep=";")

# group by numbers
custom_bioInk_count <- custom_bioInk %>%  group_by(infoProivded) %>% summarise(n_studies_report = length(unique(study_ID))) %>%  arrange(desc(n_studies_report))

custom_bioInk_count <- custom_bioInk_count %>%  
                    drop_na(infoProivded)

names(custom_bioInk_count) <- c("Information Provided", "Number of Unique Studies")

library(formattable)

formattable(custom_bioInk_count,
            align =c("l", "r"),
            list(`Indicator Name` = formatter(
              "span", style = ~ style(color = "grey",font.weight = "bold")), 
              `Number of Unique Studies`= color_bar("#b2df8a")
))
Information Provided Number of Unique Studies
Concentration 51
Composition 50
Solvent 42
Storage conditions 7
None 1
#################################
####### How many items were reported? 

custom_bioInk_studies <- custom_bioInk %>%  group_by(study_ID) %>% summarise(n_items_reported = length(unique(infoProivded))) %>%  arrange(desc(n_items_reported)) 

# hist(custom_bioInk_studies$n_items_reported)

t11 <- table(custom_bioInk_studies$n_items_reported)

#barplot(table(custom_bioInk_studies$n_items_reported), ylab = "Number of studies", cex.names=.7, col = "lightblue")

text(x = barplot(t11, ylab = "Number of studies", ylim=c(0, max(t11) + 10), cex.names=1 , col = "#b2df8a"
                 , main = "How many items were reported about custom-formulated bioink?")
     , y = t11 + 2, labels = t11, cex = 1)

Figure 3 - Liver Cells

Figure 3a - What Type of Liver Cells are used?

### combine the ones with semi-colon - into a new category called "Combination"

liver_cells <- reconciled %>% 
  mutate(`2.2 What is the main type of liver cells included?_9bea404f-a75c-401f-af5b-8fd020306538_Answer` = recode(`2.2 What is the main type of liver cells included?_9bea404f-a75c-401f-af5b-8fd020306538_Answer`, "Hepatoma cells;Other" = "Combination")) %>% 
   mutate(`2.2 What is the main type of liver cells included?_9bea404f-a75c-401f-af5b-8fd020306538_Answer` = recode(`2.2 What is the main type of liver cells included?_9bea404f-a75c-401f-af5b-8fd020306538_Answer`, "Primary cells;Other" = "Combination")) %>% 
  mutate(`2.2 What is the main type of liver cells included?_9bea404f-a75c-401f-af5b-8fd020306538_Answer` = recode(`2.2 What is the main type of liver cells included?_9bea404f-a75c-401f-af5b-8fd020306538_Answer`, "primary cells" = "Primary cells"))%>% 
  mutate(`2.2 What is the main type of liver cells included?_9bea404f-a75c-401f-af5b-8fd020306538_Answer` = recode(`2.2 What is the main type of liver cells included?_9bea404f-a75c-401f-af5b-8fd020306538_Answer`, "Induced pluripotent stem cells" = "iPSCs")) 


t9 <- table(liver_cells$`2.2 What is the main type of liver cells included?_9bea404f-a75c-401f-af5b-8fd020306538_Answer`)


t9_sorted<- t9 %>% as.data.frame() %>% arrange(factor(Var1, levels = c("Hepatoma cells", "iPSCs", "Primary cells", "Combination", "Other")))

data_bar9 <- t9_sorted$Freq
names(data_bar9) <- t9_sorted$Var1

text(x = barplot(
#  colnames<-(t(t13_sorted[-1]), t13_sorted[,1]), 
 # 'labels' <- (t(t13_sorted[-1]), t13_sorted[,1])), 
  # t(as.matrix(t13_sorted)), 
   data_bar9,
  ylab = "Number of Studies", ylim=c(0, max(data_bar9) + 10), cex.names=1 , col = "#eed4f9",
  # main = "What kind of forms are printed with this ink?"
  ), 
y = data_bar9 + 2, labels = data_bar9, 
  cex = 1)

#barplot(table(reconciled$`2.2 What is the main type of liver cells included?_9bea404f-a75c-401f-af5b-8fd020306538_Answer`), ylab = "Number of studies", cex.names=.5, col = "turquoise")

# text(x = barplot(t9, ylab = "Number of studies", ylim=c(0, max(t9) + 10), cex.names=.8 , col = "turquoise", main = "What type of Liver Cells are included?"), y = t9 + 2, labels = t9, cex = 0.8, )

Figure 3b - What cell cultures were used?

liverType <- tibble(
  study_ID = reconciled$study_ID, 
  liverCells = reconciled$`2.2 What is the main type of liver cells included?_9bea404f-a75c-401f-af5b-8fd020306538_Answer`, 
  liverCellsComment = reconciled$`2.2 What is the main type of liver cells included?_9bea404f-a75c-401f-af5b-8fd020306538_Comments`
)


# remove line breaks
library(stringr)
liverType$liverCellsComment <- str_replace_all(liverType$liverCellsComment, "[\n]" , "")
liverType <- separate_rows(liverType, liverCellsComment, sep=";")

# remove whitespace from start of str
liverType$liverCellsComment <- str_trim(liverType$liverCellsComment, "left")

# remove whitespace from end of str
liverType$liverCellsComment <- str_trim(liverType$liverCellsComment, "right")

# liverType <- liverType %>% 
#       mutate(liverCellsComment = recode(liverCellsComment, "Human iPSC-derived hepatocytes" = "human hepatocytes")) %>% 
#       mutate(liverCellsComment = recode(liverCellsComment, "adult stem cell derived hepatocytes" = "human hepatocytes")) %>% 
#   mutate(liverCellsComment = recode(liverCellsComment, "cholangiocarinoma cells" = "human cells - other")) %>% 
#   mutate(liverCellsComment = recode(liverCellsComment, "bone marrow mesenchymal cells" = "human cells - other")) %>% 
#   mutate(liverCellsComment = recode(liverCellsComment, "hepatic progenitor cells" = "human cells - other")) %>% 
#   mutate(liverCellsComment = recode(liverCellsComment, "hepatic stellate cells" = "human cells - other")) %>% 
#   mutate(liverCellsComment = recode(liverCellsComment, "Hepatocellular carcinoma" = "human cells - other")) %>% 
#     mutate(liverCellsComment = recode(liverCellsComment, "aHSC" = "human cells - other")) %>% 
#     mutate(liverCellsComment = recode(liverCellsComment, "AML12" = "human cells - other")) %>% 
#     mutate(liverCellsComment = recode(liverCellsComment, "hiHep" = "human cells - other")) %>% 
#    mutate(liverCellsComment = recode(liverCellsComment, "hESC lines RC-6 and RC-10" = "human cells - other")) %>% 
#   mutate(liverCellsComment = recode(liverCellsComment, "HMCS1SA" = "human cells - other")) %>% 
#    mutate(liverCellsComment = recode(liverCellsComment, "liver biopsies" = "human liver tissue")) %>% 
#    mutate(liverCellsComment = recode(liverCellsComment, "porcine liver tissue" = "porcine liver tissue"))

# liverType$liverCellsComment




# create categories
liverType$liverCellsComment <- as.factor(liverType$liverCellsComment)

commentsLiver <- liverType %>%  group_by(liverCellsComment) %>% summarise(n_unique = length(unique(study_ID))) %>%  arrange(desc(n_unique))


## remove NA options 
# remove NAs as they dont make sense
commentsLiver <- commentsLiver %>%  
                    drop_na(liverCellsComment)



names(commentsLiver) <- c("Type of Liver Cells", "Number of Unique Studies")


#install.packages("formattable")
library(formattable)

formattable(commentsLiver,
            align =c("l", "r"),
            list(`Indicator Name` = formatter(
              "span", style = ~ style(color = "black",font.weight = "bold")), 
              "Number of Unique Studies"= color_bar("#eed4f9")
))
Type of Liver Cells Number of Unique Studies
HepG2 26
human hepatocytes 11
HepaRG 5
murine hepatocytes 4
Hep3B 3
Huh7 2
AML12 murine cell line 1
bone marrow mesenchymal cells 1
cholangiocarinoma cells 1
hepatic progenitor cells 1
hepatic stellate cells LX2 1
Hepatocellular carcinoma 1
hESCs (RC-6, RC-10) 1
hiHep 1
HMCS1SA 1
liver biopsies 1
miHeps (mouse hepatocyte-like cells) 1
porcine liver tissue 1

Figure 3c - What Type of non-parenchymal cells were included in the co-cultures?

nonParanchymal <- tibble(
  study_ID = reconciled$study_ID, 
  nonParanchymalCellType = reconciled$`2.2.1.1 If co-cultured, what type of non-parenchymal cells are included?_b729a62f-2dc7-47b6-ada7-e1ed8e363918_Answer`, 
  Comment = reconciled$`2.2.1.1 If co-cultured, what type of non-parenchymal cells are included?_b729a62f-2dc7-47b6-ada7-e1ed8e363918_Comments`
)

nonParanchymal <- separate_rows(nonParanchymal, nonParanchymalCellType, sep="\\|")
nonParanchymal <- separate_rows(nonParanchymal, nonParanchymalCellType, sep=";")


# group by numbers
nonParanchymal_count <- nonParanchymal %>%    mutate(nonParanchymalCellType = recode(nonParanchymalCellType, "Other" = "Fibroblasts")) %>% group_by(nonParanchymalCellType) %>% summarise(n_studies_report = length(unique(study_ID))) %>%  arrange(desc(n_studies_report))



# remove NAs as they dont make sense
nonParanchymal_count <- nonParanchymal_count %>%  

                    drop_na(nonParanchymalCellType)


names(nonParanchymal_count) <- c("Paranchymal Cell Type", "Number of Unique Studies")

library(formattable)

formattable(nonParanchymal_count,
            align =c("l", "r"),
            list(`Indicator Name` = formatter(
              "span", style = ~ style(color = "black",font.weight = "bold")), 
              "Number of Unique Studies"= color_bar("#eed4f9")
))
Paranchymal Cell Type Number of Unique Studies
Endothelial cells 19
Fibroblasts 12
Hepatic stellate cells 10
Immune cells 3
Stem cells 3
Epithelial cells 1

Figure 3d - What Meta-data was provided for the Liver Cells?

Figure 3e - Additives

### Additives
# -- needs cleaning 
# table(reconciled$`4.1.3.3 Which information is provided on the additives in the ink or culture? _4c2b5908-9c3c-4ba8-91f2-dd9771ac2ad4_Answer`)
# needs cleaning

liverAdditive <- tibble(
  study_ID = reconciled$study_ID, 
  additive = reconciled$`4.1.3.3 Which information is provided on the additives in the ink or culture? _4c2b5908-9c3c-4ba8-91f2-dd9771ac2ad4_Answer`
)


liverAdditive <- separate_rows(liverAdditive, additive, sep="\\|")
liverAdditive <- separate_rows(liverAdditive, additive, sep=";")

# group by numbers
liverAdditive_count <- liverAdditive %>%  group_by(additive) %>% summarise(n_studies_report = length(unique(study_ID))) %>%  arrange(desc(n_studies_report))

names(liverAdditive_count) <- c("Liver Additive Type", "Number of Unique Studies")

library(formattable)

formattable(liverAdditive_count,
            align =c("l", "r"),
            list(`Indicator Name` = formatter(
              "span", style = ~ style(color = "black",font.weight = "bold")), 
              "Number of Unique Studies"= color_bar("#eed4f9")
))
Liver Additive Type Number of Unique Studies
Concentration 50
Manufacturer 42
None 13
Order number 10
#################################
####### How many items were reported? 

additives_studies <- liverAdditive %>%  group_by(study_ID) %>% summarise(n_items_reported = length(unique(additive))) %>%  arrange(desc(n_items_reported)) 

# hist(custom_bioInk_studies$n_items_reported)

t12 <- table(additives_studies$n_items_reported)

#barplot(table(custom_bioInk_studies$n_items_reported), ylab = "Number of studies", cex.names=.7, col = "lightblue")

text(x = barplot(t12, ylab = "Number of studies", ylim=c(0, max(t12) + 10), cex.names=.8 , col = "turquoise", main = "How many items were reported about bioink or co-culture additives?"), y = t12 + 2, labels = t12, cex = 0.8)

###################################################
## 2.1.1.1 - if xeno free

additives <- tibble(
  study_ID = reconciled$study_ID, 
  additive = reconciled$`2.1.1.1 If not xeno-free, which additives are included in the study?_39f4070b-a7cd-4b06-9618-47e07363219c_Answer`
)

additives <- separate_rows(additives, additive, sep="\\|")
additives <- separate_rows(additives, additive, sep=";")


# group by numbers
Additive_count <- additives %>%  group_by(additive) %>% summarise(n_studies_report = length(unique(study_ID))) %>%  arrange(desc(n_studies_report))

library(formattable)

formattable(Additive_count,
            align =c("l", "r"),
            list(`Indicator Name` = formatter(
              "span", style = ~ style(color = "grey",font.weight = "bold")), 
              `n_studies_report`= color_bar("turquoise")
))
additive n_studies_report
Fetal Bovine Serum (FBS) 37
Gelatin 27
NA 20
Other 12
Matrigel 9
Bovine Serum Albumin (BSA) 8
Collagen 8
Basement Membrane Extracts (BME) 1
#### 2.1.2 - Animal 

additivesAnimal <- tibble(
  study_ID = reconciled$study_ID, 
  additive = reconciled$`2.1.2 If animal, which of the following additives are included in the study?_bd00875c-4d61-4449-8629-6ff8fab20ec5_Answer`
)



additivesAnimal <- separate_rows(additivesAnimal, additive, sep="\\|")
additivesAnimal <- separate_rows(additivesAnimal, additive, sep=";")


# group by numbers
AdditiveAnimal_count <- additivesAnimal %>%  group_by(additive) %>% summarise(n_studies_report = length(unique(study_ID))) %>%  arrange(desc(n_studies_report))

library(formattable)

formattable(AdditiveAnimal_count,
            align =c("l", "r"),
            list(`Indicator Name` = formatter(
              "span", style = ~ style(color = "grey",font.weight = "bold")), 
              `n_studies_report`= color_bar("turquoise")
))
additive n_studies_report
NA 59
Fetal Bovine Serum (FBS) 3
Collagen 1
Gelatin 1
Not reported 1
Other 1
#### 2.1.3 - if both
additivesBoth <- tibble(
  study_ID = reconciled$study_ID, 
  additive = reconciled$`2.1.3 If both, which of the following additives are included in the study?_648859a8-3da6-4d7e-b457-d3443a608681_Answer`
)

additivesBoth <- separate_rows(additivesBoth, additive, sep="\\|")
additivesBoth <- separate_rows(additivesBoth, additive, sep=";")


# group by numbers
AdditiveBoth_count <- additivesBoth %>%  group_by(additive) %>% summarise(n_studies_report = length(unique(study_ID))) %>%  arrange(desc(n_studies_report))

library(formattable)

formattable(AdditiveBoth_count,
            align =c("l", "r"),
            list(`Indicator Name` = formatter(
              "span", style = ~ style(color = "grey",font.weight = "bold")), 
              `n_studies_report`= color_bar("turquoise")
))
additive n_studies_report
NA 49
Fetal Bovine Serum (FBS) 14
Gelatin 5
Bovine Serum Albumin (BSA) 2
Collagen 2
Matrigel 1
Other 1
##### Combine animal, if not xeno-free and both 

additivesCombo <- tibble(
  study_ID = reconciled$study_ID, 
  additive_xeno = reconciled$`2.1.1.1 If not xeno-free, which additives are included in the study?_39f4070b-a7cd-4b06-9618-47e07363219c_Answer`,
  additive_both = reconciled$`2.1.3 If both, which of the following additives are included in the study?_648859a8-3da6-4d7e-b457-d3443a608681_Answer`, 
    additive_animal = reconciled$`2.1.2 If animal, which of the following additives are included in the study?_bd00875c-4d61-4449-8629-6ff8fab20ec5_Answer`
  
)

additivesCombo <- separate_rows(additivesCombo, additive_xeno, sep="\\|")
additivesCombo <- separate_rows(additivesCombo, additive_xeno, sep=";")

additivesCombo <- separate_rows(additivesCombo, additive_both, sep="\\|")
additivesCombo <- separate_rows(additivesCombo, additive_both, sep=";")

additivesCombo <- separate_rows(additivesCombo, additive_animal, sep="\\|")
additivesCombo <- separate_rows(additivesCombo, additive_animal, sep=";")


### merge level 2 & merge level 3 
# additivesCombo$additives_all <- ifelse(!is.na(additivesCombo$additive_animal), additivesCombo$additive_animal, additivesCombo$additive_both)
# additivesCombo$additives_all <- ifelse(!is.na(additivesCombo$additive_both), additivesCombo$additive_both, additivesCombo$additive_xeno)


additivesCombo <-  additivesCombo %>% unite("additives_all", c("additive_animal","additive_both", "additive_xeno"), na.rm = TRUE, remove = FALSE) %>% 
  subset(study_ID != "4d390c76-69b1-4a62-9805-72659c3be47b") %>% 
  subset(study_ID != "0a879122-3ef7-4fb8-85fb-d87cd7622675")


additivesCombo_count <- additivesCombo %>%  group_by(additives_all) %>% summarise(n_studies_report = length(unique(study_ID))) %>%  arrange(desc(n_studies_report))


names(additivesCombo_count) <- c("Liver Additive Type", "Number of Unique Studies")

library(formattable)

formattable(additivesCombo_count,
            align =c("l", "r"),
            list(`Indicator Name` = formatter(
              "span", style = ~ style(color = "black",font.weight = "bold")), 
              "Number of Unique Studies"= color_bar("#eed4f9")
))
Liver Additive Type Number of Unique Studies
Fetal Bovine Serum (FBS) 54
Gelatin 33
Other 14
Collagen 11
Bovine Serum Albumin (BSA) 10
Matrigel 10
Basement Membrane Extracts (BME) 1
Not reported 1

Figure 4 - Model Conditions and Measurements

Figure 4a

t13 <- table(reconciled$`5.2 How long were the liver models cultured after printing?_1f136f0a-786b-4e17-a97d-e5cf32f47b26_Answer`)
        # < 72 hours 2 weeks - 3 months   3 days - 2 weeks       not reported 
        #          2                 16                 42                  3 
#t13 <- data.table(t13)

# manually set levels 

t13_sorted<- t13 %>% as.data.frame() %>% arrange(factor(Var1, levels = c("< 72 hours", "3 days - 2 weeks", "2 weeks - 3 months", "not reported")))

# library(data.table)

# setcolorder(t13$V1, c("< 72 hours", "3 days - 2 weeks", "2 weeks - 3 months", "not reported"))


# barplot(table(reconciled$`5.2 How long were the liver models cultured after printing?_1f136f0a-786b-4e17-a97d-e5cf32f47b26_Answer`), ylab = "Number of studies", cex.names=.5, col = "purple")

# reconciled$`5.2 How long were the liver models cultured after printing?_1f136f0a-786b-4e17-a97d-e5cf32f47b26_Answer` <- as.factor(reconciled$`5.2 How long were the liver models cultured after printing?_1f136f0a-786b-4e17-a97d-e5cf32f47b26_Answer`)
# 
# levels(reconciled$`5.2 How long were the liver models cultured after printing?_1f136f0a-786b-4e17-a97d-e5cf32f47b26_Answer`)
# 
# reconciled$`5.2 How long were the liver models cultured after printing?_1f136f0a-786b-4e17-a97d-e5cf32f47b26_Answer` <- factor(reconciled$`5.2 How long were the liver models cultured after printing?_1f136f0a-786b-4e17-a97d-e5cf32f47b26_Answer`, levels = c("< 72 hours", "3 days - 2 weeks", "2 weeks - 3 months", "not reported"))
# 
# levels(reconciled$`5.2 How long were the liver models cultured after printing?_1f136f0a-786b-4e17-a97d-e5cf32f47b26_Answer`)
# 
# reconciled2 <- reconciled[order(levels(reconciled$`5.2 How long were the liver models cultured after printing?_1f136f0a-786b-4e17-a97d-e5cf32f47b26_Answer`)),]
# 
# t13 <- table(time_coculture$`5.2 How long were the liver models cultured after printing?_1f136f0a-786b-4e17-a97d-e5cf32f47b26_Answer`)

data_bar13 <- t13_sorted$Freq
names(data_bar13) <- t13_sorted$Var1



barplot(data_bar13)

text(x = barplot(
#  colnames<-(t(t13_sorted[-1]), t13_sorted[,1]), 
 # 'labels' <- (t(t13_sorted[-1]), t13_sorted[,1])), 
  # t(as.matrix(t13_sorted)), 
   data_bar13,
  ylab = "Number of Studies", ylim=c(0, max(data_bar13) + 10), cex.names=1 , col = "#a6cee3"
  #, main = "How long were liver models cultured?"
  ), y = data_bar13 + 2, labels = data_bar13, 
  cex = 1)

Figure 4b- What Liver Proteins were measured?

# otherLiverMetabolite <- liverMetabolite_comments %>%  group_by(`6.4 Which metabolites were analyzed in the study?_5652d702-1441-4234-b37d-f0b44d64c5e9_Comments`) %>% summarise(n_unique = length(unique(study_ID))) %>%  arrange(desc(n_unique))

# otherLiverMetabolite <- otherLiverMetabolite %>% 
#   drop_na(`6.4 Which metabolites were analyzed in the study?_5652d702-1441-4234-b37d-f0b44d64c5e9_Comments`)


liverMetabolite <- tibble(
  study_ID = reconciled$study_ID, 
  metabolite = reconciled$`6.4 Which metabolites were analyzed in the study?_5652d702-1441-4234-b37d-f0b44d64c5e9_Answer`, 
  comment = reconciled$`6.4 Which metabolites were analyzed in the study?_5652d702-1441-4234-b37d-f0b44d64c5e9_Comments`
) 


liverMetabolite <- separate_rows(liverMetabolite, metabolite, sep="\\|")
liverMetabolite <- separate_rows(liverMetabolite, metabolite, sep=";")


liverMetabolite <- liverMetabolite %>%  group_by(metabolite) %>% summarise(n_unique = length(unique(study_ID))) %>%  arrange(desc(n_unique))


# remove NAs as they dont make sense
liverMetabolite <- liverMetabolite[liverMetabolite$metabolite != "None" ,]



names(liverMetabolite) <- c("Liver Metabolite Type", "Number of Unique Studies")

#install.packages("formattable")
library(formattable)

formattable(liverMetabolite,
            align =c("l", "r"),
            list(`Indicator Name` = formatter(
              "span", style = ~ style(color = "black",font.weight = "bold")), 
              "Number of Unique Studies"= color_bar("#a6cee3")
))
Liver Metabolite Type Number of Unique Studies
Albumin 47
Urea 24
Other 7
Bile acid 3
#### CLEAN THIS!! 
# formattable(otherLiverMetabolite, 
#              align = c("l", "r"), 
#              list(`Indicator Name` = formatter(
#               "span", style = ~ style(color = "grey",font.weight = "bold")), 
#               `n_unique`= color_bar("yellow")
#             
#             ))

Figure 4c - What Cytochome Isoforms were measured?

# liverCytochome <- separate_rows(reconciled, `6.2.1 If yes, which cytochrome isoforms were analysed?_62bdffd7-d9c7-4646-9f66-9510f5bf2649_Answer`
#    ,sep=";")

liverCytochome_only <- tibble(
  study_ID = reconciled$study_ID, 
  cytochrome = reconciled$`6.2.1 If yes, which cytochrome isoforms were analysed?_62bdffd7-d9c7-4646-9f66-9510f5bf2649_Answer`
) 


liverCytochome_only <- separate_rows(liverCytochome_only, cytochrome, sep="\\|")
liverCytochome_only <- separate_rows(liverCytochome_only, cytochrome, sep=";")

liverCytochome_only_1 <- liverCytochome_only %>% 
  mutate(cytochrome = recode(cytochrome, "YP2C" = "CYP2C"))%>% 
  mutate(cytochrome = recode(cytochrome, "CYP1A2" = "CYP1A"))

# liverCytochome_only_1$cytochrome <- as.factor(liverCytochome_only_1$cytochrome)

liverCytochome_only_count <- liverCytochome_only_1 %>%  group_by(cytochrome) %>% summarise(n_unique = length(unique(study_ID))) %>%  arrange(desc(n_unique))


# remove NAs as they dont make sense
liverCytochome_only_count <- liverCytochome_only_count %>%  
                    drop_na(cytochrome)


names(liverCytochome_only_count) <- c("Liver Cytochrome Type", "Number of Unique Studies")

formattable(liverCytochome_only_count,
            align =c("l", "r"),
            list(`Indicator Name` = formatter(
              "span", style = ~ style(color = "black",font.weight = "bold")), 
              "Number of Unique Studies"= color_bar("#a6cee3")
))
Liver Cytochrome Type Number of Unique Studies
CYP3A 21
CYP1A 15
CYP2C 6
CYP2B 5
CYP2D 5
CYP2E 4
Not reported 2

Figure 4d - Storage Conditions

t14 <- table(reconciled$`5.1 Does the study report the storage conditions of the printed models?_0adebee3-f3bc-4b01-a756-f8a93dc7b5bc_Answer`)


text(x = barplot(t14, ylab = "Number of Studies", ylim=c(0, max(t14) + 10), cex.names=1 , col = "#a6cee3"
                 #, main = "Were storage conditions reported?"
                 ), y = t14 + 2, labels = t14, cex = 1)

Figure 4d - Frequency of Assays Used

# 5.3.1

assays <- tibble(
  study_ID = reconciled$study_ID, 
  assay = reconciled$`5.3.1 Which assays were performed to assure the quality of the liver model?_8a415412-28c6-48ff-840a-538ea69a068f_Answer`
) 

assays <- separate_rows(assays, assay, sep="\\|")
assays <- separate_rows(assays, assay, sep=";")


assays <- assays %>%  group_by(assay) %>% summarise(n_unique = length(unique(study_ID))) %>%  arrange(desc(n_unique))


# remove NAs as they dont make sense
assays <- assays %>%  
                    drop_na(assay)

names(assays) <- c("Assay", "Number of Unique Studies")

customPurple = "#a6cee3"

formattable(assays,
            align =c("l", "r"),
            list(`Indicator Name` = formatter(
              "span", style = ~ style(color = "black",font.weight = "bold")), 
              "Number of Unique Studies"= color_bar(customPurple)
))
Assay Number of Unique Studies
Viability test 47
Histological characterization 45
Live/Dead Cell Staining 44
Enzyme linked immunosorbent Assay (ELISA) of liver markers 30
Real-time quantitative PCR of liver markers 28
Rheological test 23
Mechanical stiffness 15
Size measurement 13
Biodegradation 4
Biocompatibility 3

Figure 4e - Agonists

# 6.3.1 


agonists <- tibble(
  study_ID = reconciled$study_ID, 
  agonist = reconciled$`6.3.1  Please specify the agonists of the receptors that are applied._d42bd778-8656-4e6b-8b11-e4bdecb6a9b9_Answer`, 
  agonistsComment = reconciled$`6.3.1  Please specify the agonists of the receptors that are applied._d42bd778-8656-4e6b-8b11-e4bdecb6a9b9_Comments`
)


agonists <- separate_rows(agonists, agonist, sep="\\|")
agonists <- separate_rows(agonists, agonist, sep=";")


agonists <- separate_rows(agonists, agonistsComment, sep="\\|")
agonists <- separate_rows(agonists, agonistsComment, sep=";")

# remove line breaks
agonists$agonistsComment <- str_replace_all(agonists$agonistsComment, "[\n]" , "")
# remove whitespace from start of str
agonists$agonistsComment <- str_trim(agonists$agonistsComment, "left")

# remove whitespace from end of str
agonists$agonistsComment <- str_trim(agonists$agonistsComment, "right")

agonists_count <- agonists %>%  group_by(agonist) %>% summarise(n_unique = length(unique(study_ID))) %>%  arrange(desc(n_unique))


# remove NAs/None as they dont make sense
# liverMetabolite <- liverMetabolite[liverMetabolite$metabolite != "None" ,]

names(agonists_count) <- c("Agonist", "Number of Unique Studies")

#install.packages("formattable")
library(formattable)

customPurple = "#a6cee3"

# formattable(agonists_count,
#             align =c("l", "r"),
#             list(`Indicator Name` = formatter(
#               "span", style = ~ style(color = "grey",font.weight = "bold")), 
#               "Number of Unique Studies"= color_bar(customPurple)
# ))



table(agonists$agonistsComment)
## 
## Acetaminophen    Omeprazole phenobarbital    rifampicin    Rifampicin 
##             1             2             1             1             6
# agonists$study_ID

agonists <- agonists %>%  
mutate(agonistsComment = recode(agonistsComment, "rifampicin" = "Rifampicin")) %>% 
mutate(agonistsComment = recode(agonistsComment, "Rifampicin " = "Rifampicin")) %>%   
  mutate(agonistsComment = recode(agonistsComment, "phenobarbital" = "Phenobarbital")) %>%
  mutate(agonistsComment = recode(agonistsComment, "Acetaminophen" = NA)) %>%
subset(study_ID != "0a2dc2f4-21ea-4770-bdf8-999c5be9a300")
## Warning: There was 1 warning in `mutate()`.
## ℹ In argument: `agonistsComment = recode(agonistsComment, Acetaminophen = NA)`.
## Caused by warning:
## ! Unreplaced values treated as NA as `.x` is not compatible.
## Please specify replacements exhaustively or supply `.default`.
agonists_comment_count <- agonists %>%  group_by(agonistsComment) %>% summarise(n_unique = length(unique(study_ID))) %>%  arrange(desc(n_unique))



# remove NAs as they dont make sense
agonists_comment_count <- agonists_comment_count %>%  
                    drop_na(agonistsComment)


names(agonists_comment_count) <- c("Agonist", "Number of Unique Studies")

customPurple = "#a6cee3"

formattable(agonists_comment_count,
            align =c("l", "r"),
            list(`Indicator Name` = formatter(
              "span", style = ~ style(color = "grey",font.weight = "bold")), 
              "Number of Unique Studies"= color_bar(customPurple)
))
Agonist Number of Unique Studies

Figure 5 - Applications

# Application 
t15 <- table(reconciled$`7.1 Do the authors apply the model in the study?_a6895d38-a9ed-4605-a092-4f06ebbd9e2b_Answer`)
 # No Yes 
 # 35  28 



text(x = barplot(t15, ylab = "Number of Studies", ylim=c(0, max(t15) + 10), cex.names=.8 , col = "gray", main = "Do authors apply the model in the study?"), y = t15 + 2, labels = t15, cex = 0.8)

###########################################################
# field of application 
#table(reconciled$`7.1.1 please select the field of application. _d332c2ee-9864-434f-8595-90305808e32d_Answer`)


applications <- tibble(
  study_ID = reconciled$study_ID, 
  application = reconciled$`7.1.1 please select the field of application. _d332c2ee-9864-434f-8595-90305808e32d_Answer`
)


applications <- separate_rows(applications, application, sep="\\|")
applications <- separate_rows(applications, application, sep=";")

applications_count <- applications %>%  group_by(application) %>% summarise(n_unique = length(unique(study_ID))) %>%  arrange(desc(n_unique))


# remove NAs/None as they dont make sense
# liverMetabolite <- liverMetabolite[liverMetabolite$metabolite != "None" ,]
applications_count <- applications_count %>%  
                    drop_na(application)

names(applications_count) <- c("Application", "Number of Unique Studies")

#install.packages("formattable")
library(formattable)

customPurple = "#a6cee3"

formattable(applications_count,
            align =c("l", "r"),
            list(`Indicator Name` = formatter(
              "span", style = ~ style(color = "black",font.weight = "bold")), 
              "Number of Unique Studies"= color_bar(customPurple)
))
Application Number of Unique Studies
Toxicity testing 15
Drug dosage testing 9
Disease modeling 5
Other 4
Xenograft (implantation into animal) 3
Implant / Medical surgery 1

Supplementary Figures

Cell Types Over Times

# same cells as figure 3a & 3b
# 
# reconciled[,40] <- as.character(reconciled[,40])
# 
# reconciled
# 
# reconciled$`2.2 What is the main type of liver cells included?_9bea404f-a75c-401f-af5b-8fd020306538_Answer`

liver_cells <- reconciled %>% 
#  mutate(`2.2 What is the main type of liver cells included?_9bea404f-a75c-401f-af5b-8fd020306538_Answer` = recode(`2.2 What is the main type of liver cells included?_9bea404f-a75c-401f-af5b-8fd020306538_Answer`,  "Hepatoma cells;Other" = "Combination")) 
# %>% 
   mutate(`2.2 What is the main type of liver cells included?_9bea404f-a75c-401f-af5b-8fd020306538_Answer` = recode(`2.2 What is the main type of liver cells included?_9bea404f-a75c-401f-af5b-8fd020306538_Answer`, "Primary cells;Other" = "Combination")) %>% 
  mutate(`2.2 What is the main type of liver cells included?_9bea404f-a75c-401f-af5b-8fd020306538_Answer` = recode(`2.2 What is the main type of liver cells included?_9bea404f-a75c-401f-af5b-8fd020306538_Answer`, "primary cells" = "Primary cells"))%>% 
  mutate(`2.2 What is the main type of liver cells included?_9bea404f-a75c-401f-af5b-8fd020306538_Answer` = recode(`2.2 What is the main type of liver cells included?_9bea404f-a75c-401f-af5b-8fd020306538_Answer`, "Induced pluripotent stem cells" = "iPSCs")) 


t9 <- table(liver_cells$`2.2 What is the main type of liver cells included?_9bea404f-a75c-401f-af5b-8fd020306538_Answer`)


t9_sorted<- t9 %>% as.data.frame() %>% arrange(factor(Var1, levels = c("Hepatoma cells", "iPSCs", "Primary cells", "Combination", "Other")))

data_bar9 <- t9_sorted$Freq
names(data_bar9) <- t9_sorted$Var1




printer_form_year<- table(printer_forms$`4.1.4 What kind of forms are printed with this ink?_01d3ca37-1e2f-4087-8f39-c183f98f0c4e_Answer`, printer_forms$NA_Year)


printer_form_yearDF <- as.data.frame(printer_form_year)
# long to wide 
printer_form_yearDF <- printer_form_yearDF %>% spread(
   key = Var2, 
   value = Freq)


# printer_form_yearDF 
# names(printer_form_yearDF) <- gsub(x = names(printer_form_yearDF), pattern = "X", replacement = "")  


library(formattable)

formattable(printer_form_yearDF,
            #align =c("l", "r"),
            list(
              `Indicator Name` = formatter(
              "span", 
              style = ~ style(color = "grey",font.weight = "bold")), 
             area(row = 1:4) ~ color_tile("white", "green")))
## Warning in gradient(as.numeric(x), ...): NAs introduced by coercion
Var1 2010 2011 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022
Grid 0 0 0 1 0 3 4 4 1 5 5 0
Lobular Liver 0 0 0 0 0 1 0 3 1 2 2 1
Other 1 1 1 0 1 4 2 6 3 5 2 3
Toroids 0 0 0 0 1 0 0 0 0 0 0 0

Printer Forms Over Times

printer_form_year<- table(printer_forms$`4.1.4 What kind of forms are printed with this ink?_01d3ca37-1e2f-4087-8f39-c183f98f0c4e_Answer`, printer_forms$NA_Year)


printer_form_yearDF <- as.data.frame(printer_form_year)
# long to wide 
printer_form_yearDF <- printer_form_yearDF %>% spread(
   key = Var2, 
   value = Freq)


# printer_form_yearDF 
# names(printer_form_yearDF) <- gsub(x = names(printer_form_yearDF), pattern = "X", replacement = "")  


library(formattable)

formattable(printer_form_yearDF,
            #align =c("l", "r"),
            list(
              `Indicator Name` = formatter(
              "span", 
              style = ~ style(color = "grey",font.weight = "bold")), 
             area(row = 1:4) ~ color_tile("white", "green")))
## Warning in gradient(as.numeric(x), ...): NAs introduced by coercion
Var1 2010 2011 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022
Grid 0 0 0 1 0 3 4 4 1 5 5 0
Lobular Liver 0 0 0 0 0 1 0 3 1 2 2 1
Other 1 1 1 0 1 4 2 6 3 5 2 3
Toroids 0 0 0 0 1 0 0 0 0 0 0 0